#NoTrayIcon 
Gui, show, w250 h340 X820 Y100, PT XP Calc by Gavan
Gui, Add, Edit, R12 ReadOnly W200 vMyEdit
Gui, Add, Progress, w20 h160 Vertical Range0-160 vGuessBar
gui, add, text, w30 vGuessText, 
gui, add, Checkbox, gPauseCalc vPauseButton, Pause
Gui, Add, GroupBox, w220 h120 vGroupBox, TNL Calc
gui, add, Text, vStartExpText w210, XP on Entry Start:                          Million
gui, add, Edit, vStartExpBox w70,0
gui, add, Text, vLevelExpText w210, XP on Level Up:                            Million
gui, add, Edit, vLevelExpBox w70,0
gui, add, Text, vTillNextLevel w210 r2
Gui, Add, Slider, gTickChange Invert TickInterval1 vTickSlider w70 Range1-6, 3
gui, add, Text, vTickSliderText1 w15, Add:
gui, add, Text, vTickSliderText2 w60 r2, 1m`nEach Entry

GuiControl, MoveDraw, MyEdit, x10 y10
GuiControl, MoveDraw, GuessBar, x220 y12
GuiControl,,Tick1m,1
GuiControl, MoveDraw, PauseButton, x160 y180
GuiControl, MoveDraw, GuessText, x220 y180
GuiControl, MoveDraw, GroupBox, x10 y205
GuiControl, MoveDraw, StartExpText, x15 y230
GuiControl, MoveDraw, StartExpBox, x105 y225
GuiControl, MoveDraw, LevelExpText, x15 y260
GuiControl, MoveDraw, LevelExpBox, x105 y255
GuiControl, MoveDraw, TillNextLevel, x15 y290
GuiControl, MoveDraw, TickSlider, x30 y174
GuiControl, MoveDraw, TickSliderText1, x8 y180
GuiControl, MoveDraw, TickSliderText2, x100 y180
pertick = 1000000
settimer, TickChange, 100
settimer, guessxp, 1000

;-----time to level calc-------
TimeToLevel(){
GuiControlGet, LevelExp, , LevelExpBox
GuiControlGet, StartExp, , StartExpBox
global timer1
global timer2
global count
global xpps
global guesscurrentxp
TNL := ((LevelExp - StartExp) - count) - guesscurrentxp
TTL := Round((TNL * 1000000) / xpps)
leveluptime1 := A_Now
EnvAdd, leveluptime1, TTL, seconds
FormatTime, leveluptime, %leveluptime1%, h:mm:ss tt
hours := Floor(TTL / 3600)
minutes := Floor((TTL - (hours * 3600)) / 60)
seconds := TTL
seconds -= (hours * 3600)
seconds -= (minutes * 60)

if(TTL > 0){
txt := "Next Level in: "
}else{
txt := ""
}
if(TTL < 3600){
hours := ""
}else{
hours := hours . "h "
}
if(TTL < 60){
minutes := ""
}else{
minutes := minutes . "m "
}
if (TTL < 1){
if (LevelExp >= 1 && count > 0){
seconds := "GZ, Level Up!!, now input your next level xp"
}else{
seconds := ""
}
}else{
seconds := seconds . "s"
}
if (LevelExp > 0 && count > 0){
GuiControl,, TillNextLevel, %txt%%hours%%minutes%%seconds%`nat %leveluptime%
}else{
GuiControl,, TillNextLevel, Input a number to show Time to Level`, use`n decimals if you have to. (recalc on entry)
}
}
;----end time to level--------


;----convert large numbers to a number with a comma-----------
Commas(num1a){
if(num1a < 1000){
return num1a
}else if(num1a < 10000){
num1b := SubStr(num1a,1,1) . "," . SubStr(num1a,2)
return num1b
}else if(num1a < 100000){
num1b := SubStr(num1a,1,2) . "," . SubStr(num1a,3)
return num1b
}else if(num1a < 1000000){
num1b := SubStr(num1a,1,3) . "," . SubStr(num1a,4)
return num1b
}else if(num1a < 10000000){
num1b := SubStr(num1a,1,1) . "," . SubStr(num1a,2,3) . "," . SubStr(num1a,5)
return num1b
}else if(num1a < 100000000){
num1b := SubStr(num1a,1,2) . "," . SubStr(num1a,3,3) . "," . SubStr(num1a,6)
return num1b
}else if(num1a < 1000000000){
num1b := SubStr(num1a,1,3) . "," . SubStr(num1a,4,3) . "," . SubStr(num1a,7)
return num1b
}

}
;--------------end comma function--------------------



;----------run on startup and when reset hotkey pressed---------------
start:
entryxp = 0
timer1 = 0
count = 0
timer2 = 0
GuiControl,,GuessBar, 0
GuiControl,,GuessText, 
GuiControl,, MyEdit, No Entry yet`n`nAdd Entry`nShift+Middle Mouse`nShift+Numpad+`n`nClear / New`nCtrl+Middle Mouse`nCtrl+Numpad+`n`nPause: Ctrl+P
GuiControl,,TillNextLevel,Input a number to show Time to Level`, use`n decimals if you have to. (recalc on entry)
return
;--------end startup and reset--------



;----radio boxes click----
TickChange:
GuiControlGet, TickSliderValCheck, , TickSlider
if(TickSliderValCheck = TickSliderVal){
return
}

GuiControlGet, TickSliderVal, , TickSlider
if(TickSliderVal = 6){
GuiControl,,TickSliderText2,1k`nEach Entry
pertick := 1000
}else if(TickSliderVal = 5){

GuiControl,,TickSliderText2,10k`nEach Entry
pertick := 10000
}else if(TickSliderVal = 4){

GuiControl,,TickSliderText2,100k`nEach Entry
pertick := 100000
}else if(TickSliderVal = 3){

GuiControl,,TickSliderText2,1m`nEach Entry
pertick := 1000000
}else if(TickSliderVal = 2){

GuiControl,,TickSliderText2,10m`nEach Entry
pertick := 10000000
}else if(TickSliderVal = 1){

GuiControl,,TickSliderText2,100m`nEach Entry
pertick := 100000000
}





;GuiControlGet, radio10m, , Tick10m
;GuiControlGet, radio1m, , Tick1m
;GuiControlGet, radio100k, , Tick100k
;radionum1 := radio10m . radio1m . radio100k ; create a number from radio buttons binary
;pertick := radionum1 * 100000


Recalc()
return
;---end checkbox---

;-----pause button----
PauseCalc:
GuiControlGet, PauseButtonVal, , PauseButton
if(PauseButtonVal){
PauseTimer = %A_TickCount%
GuiControl, Disable, MyEdit
GuiControl, Disable, GuessBar
GuiControl, Disable, Tick10m
GuiControl, Disable, Tick1m
GuiControl, Disable, Tick100k
GuiControl, Disable, GuessText
settimer, guessbar, off
settimer, guessxp, off

}else{
PauseAdd := (A_TickCount - PauseTimer)
timer1 := (timer1 + PauseAdd)
timer2 := (timer2 + PauseAdd)
timer22 := (timer22 + PauseAdd)
GuiControl, Enable, MyEdit
GuiControl, Enable, GuessBar
GuiControl, Enable, Tick10m
GuiControl, Enable, Tick1m
GuiControl, Enable, Tick100k
GuiControl, Enable, GuessText
ReCalc()
settimer, guessbar, 100
settimer, guessxp, 1000
pauselog := Round(PauseAdd / 1000,2)
FileAppend, Paused for %pauselog% Seconds`n, Logs\%logname%

}

return
;----end pause calc-----


;----recalc stuff----
Recalc(){
global secondsbetween
global entryxp
global timer1
global timer2
global timer22

secondsbetween := (timer2 - timer1) / 1000

xpps := (entryxp / secondsbetween)


}
;----end recalc-----

+MButton::
+NumPadAdd::
entrycheck := A_TickCount - timer2
if(entrycheck < 500){
return
}

FormatTime, thistime, %A_Now%, yyyy-MM-dd HH-mm-ss
if (timer1 = 0) {
;----------First Entry Click-----------
logname = %thistime%.txt
timer1 = %A_TickCount%
timer2 := timer1
GuiControl,, MyEdit, Start-----
IfNotExist, Logs
FileCreateDir, Logs
FileAppend, %thistime% - start`n, Logs\%logname%
}else{
;----------normal entry add-------
entryxp += pertick
count :=  round((entryxp / 1000000),4)
timer22 := timer2
timer2 = %A_TickCount%
thistick := (timer2 - timer22) / 1000
thisxpps := round(pertick / ((timer2 - timer22) / 1000), 1)
secondsbetween := (timer2 - timer1) / 1000
;EnvSub, secondsbetween, %timer1%, Seconds
xpps := (entryxp / secondsbetween)
secs := round(secondsbetween / count, 1)
GuiControlGet, StartExp, , StartExpBox
if(StartExp < 0){
StartExp = 0
}
;------round xp count number to lowest decimal-------
roundcount := 0
loop,3{
modz := Mod((StartExp + count) * (10**(A_Index - 1)),1)
if(modz != "0.000000" && modz != "1.000000"){
roundcount := A_Index
}
}
;------end round xp count----------
editbox := "current xp: " . round((StartExp + count),roundcount) . "m`navg sec's per mil: " . secs . "`navg XP/s: " . Round(xpps)
GuiControl,, MyEdit, %editbox%
commathisxpps := Commas(thisxpps)
commaxpps := Commas(round(xpps))
thislog := thistime . " - current xp: " . count . "m - this tick took " . Round(thistick, 1) . " secs - this XP/s: " . commathisxpps . "`n"
avglog := thistime . " - total xp: " . count . "m - average per mil: " . secs . " secs - average XP/s: " . commaxpps
FileAppend, %thislog%, Logs\%logname%
closingstatement = %avglog%
GuiControl,,GuessBar, 0
settimer, guessbar, 100
;------entry end-------
}
SoundPlay, record.mp3
return

guessbar:
if(entryxp > 0){

guesstime := (((pertick / xpps) * 1000) + timer2)

guessbarvalue := (160 / (guesstime - timer2))
currentguess := round((A_TickCount - timer2) * guessbarvalue)
GuiControl,,GuessBar, %currentguess%
guesstextval := floor((guesstime - A_TickCount) / 1000)
GuiControl,,GuessText, %guesstextval%
}
return
guessxp:
guesscurrentxp := (((A_TickCount - timer2) / 1000000000) * xpps)
TimeToLevel()
return

^MButton::
^NumpadAdd::
settimer,guessbar,off
FileAppend, %closingstatement%, Logs\%logname%
SoundPlay, reset.mp3
goto start

return
^p::
GuiControlGet, PauseButtonVal, , PauseButton
if(PauseButtonVal){
GuiControl,,PauseButton,0
goto PauseCalc
}else{
GuiControl,,PauseButton,1
goto PauseCalc
}
SoundPlay, record.mp3
return

guiclose:
if (count > 0) {
FileAppend, %closingstatement%, Logs\%logname%
}
exitapp
